began_experiment_ipw <- supp_df %>% filter(all_players_finish == T, pub_official_indicator == 1) %>% mutate(group.treatment = factor(group.treatment, levels = c("random", "merit", "patronage")))

keep_bivariate <-lm(group.dictator_payoff/1000 ~ factor(group.treatment), began_experiment_ipw, weights = ipw)
herf_bivariate <- lm(herf_index_payout ~ factor(group.treatment), began_experiment_ipw, weights = ipw)
other_bivariate <- lm(perc_other ~ factor(group.treatment), began_experiment_ipw, weights = ipw)

observations <- c(nobs(keep_bivariate),nobs(herf_bivariate),nobs(other_bivariate))

keep_bivariate <- coeftest(keep_bivariate, vcov=vcovHC(keep_bivariate,type="HC0"))
herf_bivariate <- coeftest(herf_bivariate, vcov=vcovHC(herf_bivariate,type="HC0"))
other_bivariate <- coeftest(other_bivariate, vcov=vcovHC(other_bivariate,type="HC0"))


table <- list(keep_bivariate, herf_bivariate, other_bivariate)

note_text <- paste("Beta coefficients from OLS regression with IPW weights. Standard errors were calculated using the Huber-White (HC0) correction. 
                   The outcomes measures are the (1) absolute sum kept by the public officials; (2) a herfindahl index of participant shares; (3) the percent
                   of money given to other participants.")

table = stargazer(table, type = 'latex', 
                  title = "The Effect of Selection Mode on Pro-Sociality, IPS Weights",
                  label = 'tab:pro_soc_ipw',
                  model.names = F,
                  model.numbers = T,
                  digits = 3,
                  column.separate = c(1,1, 1),
                  column.labels = c("Keep (IDR, k)", "Herf. Index (0-1)", "Share (\\%)"),
                  dep.var.labels = NULL, 
                  add.lines = list(c("Covariates", "N", "N", "N"),
                                   c("Observations", observations)),
                  covariate.labels = c("Treatment: Merit", "Treatment: Patronage", "Intercept (Reference: Random)"),
                  
                  #star.cutoffs = c(0.05, 0.01),
                  #float.env = 'sidewaystable',
                  keep.stat = c("n"),
                  notes = NULL,
                  notes.align = 'l')

write_latex(table[-c(10, 11, 12, 18, 21, 24, 30)], note_text, './outputs/tables/table_a11.tex', .8)


